#include<bits/stdc++.h>

using namespace std;

class Solution {
public:
    int balancedStringSplit(string s) {
        int cnt = 0;
        int num = 0;

        int i = 0;
        while (i < s.size())
        {
            if (s[i] == 'R') {
                num--;
            }
            else
            {
                num++;
            }
            if (i!=0&&num == 0)
            {
                cnt++;
            }
            i++;
        }

        return cnt;
    }
};